'''
Author: didiplus
Description: 
Date: 2025-08-20 20:54:00
LastEditors: didiplus
LastEditTime: 2025-08-21 21:35:28
FilePath: /WeChatBot/app/schemas/user.py
Version: 1.0
'''
from pydantic import BaseModel, EmailStr, Field
from typing import Optional, List
from datetime import datetime

class UserBase(BaseModel):
    """
    用户基础模型
    """
    username: str = Field(..., min_length=3, max_length=50, description="用户名")
    email: Optional[EmailStr] = Field(None, max_length=100, description="邮箱地址")
    nickname: Optional[str] = Field(None, max_length=100, description="用户昵称")

class UserCreate(UserBase):
    """
    用户创建模型
    """
    password: str = Field(..., min_length=6, max_length=100, description="密码")

class UserUpdate(BaseModel):
    """
    用户更新模型
    """
    email: Optional[EmailStr] = Field(None, max_length=100, description="邮箱地址")
    nickname: Optional[str] = Field(None, max_length=100, description="用户昵称")
    is_active: Optional[bool] = Field(None, description="是否激活")
    is_superuser: Optional[bool] = Field(None, description="是否为超级用户")

class UserInDBBase(UserBase):
    """
    用户数据库基础模型
    """
    id: int = Field(..., description="用户ID")
    is_active: bool = Field(True, description="是否激活")
    is_superuser: bool = Field(False, description="是否为超级用户")
    created_at: Optional[datetime] = Field(None, description="创建时间")
    updated_at: Optional[datetime] = Field(None, description="更新时间")

    class Config:
        orm_mode = True

class User(UserInDBBase):
    """
    用户返回模型
    """
    pass

class UserInDB(UserInDBBase):
    """
    用户数据库模型
    """
    password_hash: str = Field(..., description="密码哈希值")

class UserLogin(BaseModel):
    """
    用户登录模型
    """
    username: str = Field(..., description="用户名")
    password: str = Field(..., description="密码")

class Token(BaseModel):
    """
    访问令牌模型
    """
    access_token: str = Field(..., description="访问令牌")
    token_type: str = Field("bearer", description="令牌类型")

class TokenData(BaseModel):
    """
    令牌数据模型
    """
    user_id: Optional[int] = Field(None, description="用户ID")
    username: Optional[str] = Field(None, description="用户名")





class TokenVerifyResponse(BaseModel):
    valid: bool
    user_id: Optional[int] = None
    username: Optional[str] = None